home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / hpljii.trm < prev    next >
Text File  |  1993-09-15  |  8KB  |  326 lines

  1. /*
  2.  * $Id: hpljii.trm%v 3.50.1.11 1993/08/10 03:55:03 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - hpljii.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  hpljii, hpdj
  26.  *
  27.  * AUTHORS
  28.  *  John Engels
  29.  *  Russell Lang
  30.  *  Maurice Castro
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  * 
  34.  */
  35.  
  36. /* The following HP laserjet series II driver uses generic bit mapped graphics
  37.    routines from bitmap.c to build up a bit map in memory.  The driver
  38.    interchanges colomns and lines in order to access entire lines
  39.    easily and returns the lines to get bits in the right order :
  40.    (x,y) -> (y,XMAX-1-x). */
  41. /* This interchange is done by calling b_makebitmap() with reversed 
  42.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  43.    will then perform the interchange before each pixel is plotted */
  44. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  45.    of Jyrki Yli-Nokari */
  46.  
  47. #ifdef HPLJII
  48.  
  49. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  50.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  51.  
  52. #define HPLJII_DPP (hplj_dpp)   /* dots per pixel */
  53. #define HPLJII_PPI (300/HPLJII_DPP) /* pixel per inch */
  54. /* make XMAX and YMAX a multiple of 8 */
  55. #define HPLJII_XMAX (8*(unsigned int)(xsize*1920/HPLJII_DPP/8.0+0.9))
  56. #define HPLJII_YMAX (8*(unsigned int)(ysize*1920/HPLJII_DPP/8.0+0.9))
  57.  
  58. #define HPLJII_VCHAR (HPLJII_PPI/6) /* Courier font with 6 lines per inch */
  59. #define HPLJII_HCHAR (HPLJII_PPI/10) /* Courier font with 10 caracters
  60.                                         per inch */
  61.  
  62. /* default values for term_tbl */
  63. #define HPLJII_75PPI_XMAX (1920/4)
  64. #define HPLJII_75PPI_YMAX (1920/4)
  65. #define HPLJII_75PPI_HCHAR (1920/4/6)
  66. #define HPLJII_75PPI_VCHAR (1920/4/10)
  67. #define HPLJII_75PPI_VTIC 5
  68. #define HPLJII_75PPI_HTIC 5
  69.  
  70.  
  71. #define HPLJII_PUSH_CURSOR fprintf(outfile,"\033&f0S") /* Save current
  72.                   cursor position */
  73. #define HPLJII_POP_CURSOR fprintf(outfile,"\033&f1S") /* Restore
  74.                   cursor position */
  75. #define HPLJII_COURIER fprintf(outfile,"\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D")
  76.          /* be sure to use courier font with 6lpi and 10cpi */
  77.  
  78. static int hplj_dpp=4;
  79. /* bm_pattern not appropriate for 300ppi graphics */
  80. static unsigned int b_300ppi_pattern[] = {0xffff, 0x1111,
  81.         0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff};
  82.  
  83. HPLJIIoptions()
  84. {
  85. char opt[4];
  86. int parse_error=0;
  87.  
  88.     if (END_OF_COMMAND) {
  89.         term_options[0]='\0';
  90.     } else {
  91.         if (token[c_token].length>3) {
  92.             parse_error=1; /* see below */
  93.         } else {
  94.         /* almost_equals() won't accept numbers - use strcmp() instead */
  95.         capture(opt,c_token,c_token);
  96.         if (!strcmp(opt,"75")) {
  97.                hplj_dpp = 4;
  98.         }
  99.         else if (!strcmp(opt,"100")) {
  100.                hplj_dpp = 3;
  101.         }
  102.         else if (!strcmp(opt,"150")) {
  103.                hplj_dpp = 2;
  104.         }
  105.         else if (!strcmp(opt,"300")) {
  106.                hplj_dpp = 1;
  107.         } else {
  108.         /* error, but set dpi anyway, since term it already set */
  109.                 parse_error=1;
  110.         }
  111.         c_token++;
  112.     }
  113.     }
  114.  
  115.     term_tbl[term].xmax = HPLJII_XMAX;
  116.     term_tbl[term].ymax = HPLJII_YMAX;
  117.     switch(hplj_dpp) {
  118.         case 1:
  119.             strcpy(term_options,"300");
  120.             term_tbl[term].v_tic = 15;
  121.             term_tbl[term].h_tic = 15;
  122.             break;
  123.         case 2:
  124.             strcpy(term_options,"150");
  125.             term_tbl[term].v_tic = 8;
  126.             term_tbl[term].h_tic = 8;
  127.             break;
  128.         case 3:
  129.             strcpy(term_options,"100");
  130.             term_tbl[term].v_tic = 6;
  131.             term_tbl[term].h_tic = 6;
  132.             break;
  133.         case 4:
  134.             strcpy(term_options,"75");
  135.             term_tbl[term].v_tic = 5;
  136.             term_tbl[term].h_tic = 5;
  137.             break;
  138.     }
  139.  
  140.     if( parse_error ) 
  141.         int_error("expecting dots per inch size 75, 100, 150 or 300",
  142.                 c_token);
  143. }
  144.  
  145.  
  146. HPLJIIinit()
  147. {
  148. #ifdef REOPEN_BINARY
  149.    reopen_binary();
  150. #endif /* REOPEN_BINARY */
  151. }
  152.  
  153.  
  154. HPLJIIgraphics()
  155. {
  156.    term_tbl[term].v_char = HPLJII_VCHAR;
  157.    term_tbl[term].h_char = HPLJII_HCHAR;
  158.    HPLJII_COURIER;
  159.    HPLJII_PUSH_CURSOR;
  160.    /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  161.       setting b_rastermode to TRUE */
  162.    b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  163.    b_rastermode = TRUE;
  164. }
  165.  
  166.  
  167. /* HPLJIItext by rjl - no compression */
  168. HPLJIItext()
  169. {
  170.   register int x,j,row;
  171.  
  172.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  173.    HPLJII_POP_CURSOR;
  174.    fprintf(outfile, "\033*r1A");
  175.  
  176.    /* dump bitmap in raster mode */
  177.    for (x = b_xsize-1; x >= 0; x--) {
  178.       row = (b_ysize/8)-1;
  179.       fprintf(outfile, "\033*b0m%dW", b_ysize/8);
  180.       for (j = row; j >= 0; j--) {
  181.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  182.       }
  183.    }
  184.    fprintf(outfile, "\033*rB");
  185.  
  186.    b_freebitmap();
  187.  
  188. #ifndef vms  /* most vms spoolers add a formfeed character */
  189.    fprintf(outfile,"\f");
  190. #endif /* not vms */
  191. }
  192.  
  193.  
  194.  
  195. HPLJIIlinetype(linetype)
  196. int linetype;
  197. {
  198.  
  199.    if (hplj_dpp == 1) {
  200.       if (linetype>=7)
  201.           linetype %= 7;
  202.       /* b_pattern not appropriate for 300ppi graphics */
  203.       b_linemask = b_300ppi_pattern[linetype+2];
  204.       b_maskcount=0;
  205.    }
  206.    else {
  207.       b_setlinetype(linetype);
  208.    }
  209. }
  210.  
  211. #define HPLJIImove b_move
  212. #define HPLJIIvector b_vector
  213. #define HPLJIItext_angle b_text_angle
  214.  
  215. HPLJIIput_text(x,y,str)
  216. unsigned int x, y;
  217. char *str;
  218. {
  219.    switch (b_angle) {
  220.       case 0:
  221.          y -= HPLJII_VCHAR/5;
  222.          HPLJII_POP_CURSOR;
  223.          HPLJII_PUSH_CURSOR;
  224.          /* (0,0) is the upper left point of the paper */
  225.          fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  226.                                          ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  227.          fputs(str, outfile);
  228. /*       for (; *str; ++str, x += HPLJII_HCHAR)
  229.             HPLJIIputc (x, y, *str, b_angle);*/
  230.          break;
  231.       case 1:
  232.          y += (HPLJII_HCHAR-2*HPLJII_VCHAR)/2;
  233.          y += (HPLJII_VCHAR+HPLJII_HCHAR)*strlen(str)/2;
  234.          for (; *str; ++str, y -= HPLJII_VCHAR)
  235.             HPLJIIputc (x, y, *str, b_angle);
  236.          break;
  237.    }
  238. }
  239.  
  240. HPLJIIputc(x,y,c,angle)
  241. unsigned int x,y;
  242. int angle;
  243. char c;
  244. {
  245.    HPLJII_POP_CURSOR;
  246.    HPLJII_PUSH_CURSOR;
  247.    /* (0,0) is the upper left point of the paper */
  248.    fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  249.                                    ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  250.    fputc(c, outfile);
  251. }
  252.  
  253.  
  254. HPLJIIreset()
  255. {
  256. #ifdef vms
  257.    fflush_binary();
  258. #endif /* vms */
  259. }
  260.  
  261.  
  262. /* HP DeskJet routines */
  263. HPDJgraphics()
  264. {
  265.     switch(hplj_dpp) {
  266.         case 1:
  267.             b_charsize(FNT13X25);
  268.             term_tbl[term].v_char = FNT13X25_VCHAR;
  269.             term_tbl[term].h_char = FNT13X25_HCHAR;
  270.             break;
  271.         case 2:
  272.             b_charsize(FNT13X25);
  273.             term_tbl[term].v_char = FNT13X25_VCHAR;
  274.             term_tbl[term].h_char = FNT13X25_HCHAR;
  275.             break;
  276.         case 3:
  277.             b_charsize(FNT9X17);
  278.             term_tbl[term].v_char = FNT9X17_VCHAR;
  279.             term_tbl[term].h_char = FNT9X17_HCHAR;
  280.             break;
  281.         case 4:
  282.             b_charsize(FNT5X9);
  283.             term_tbl[term].v_char = FNT5X9_VCHAR;
  284.             term_tbl[term].h_char = FNT5X9_HCHAR;
  285.             break;
  286.     }
  287.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  288.     setting b_rastermode to TRUE */
  289.     b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  290.     b_rastermode = TRUE;
  291. }
  292.  
  293.  
  294. /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
  295.    hopefully compatible with other HP Deskjet printers */
  296. HPDJtext()
  297. {
  298.   register int x,j,row;
  299.  
  300.    fprintf(outfile,"\033*b0M");
  301.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  302.    fprintf(outfile, "\033*r1A");
  303.  
  304.    /* dump bitmap in raster mode */
  305.    for (x = b_xsize-1; x >= 0; x--) {
  306.       row = (b_ysize/8)-1;
  307.       fprintf(outfile, "\033*b%dW", b_ysize/8);
  308.       for (j = row; j >= 0; j--) {
  309.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  310.       }
  311.    }
  312.    fprintf(outfile, "\033*rbC");
  313.  
  314.    b_freebitmap();
  315.  
  316. #ifndef vms  /* most vms spoolers add a formfeed character */
  317.    fprintf(outfile,"\f");
  318. #endif /* not vms */
  319. }
  320.  
  321. #define HPDJtext_angle b_text_angle
  322. #define HPDJput_text b_put_text
  323.  
  324. #endif /* HPLJII */
  325.  
  326.